package com.kangkang.generic;

class Student {
    public Student() {
        System.out.println("Student 构造函数");
    }
}
class Teacher {
    public Teacher() {
        System.out.println("Teacher 构造函数");
    }
}
public class Test3 {
    //Class类封装另一个类信息
    //反射:传一个Class类对象,根据class创建具体的对象
    //定义泛型方法
    public static <T> T getObj(Class<T> c) {
        T obj = null;
        try {
            //c.newInstance();  1.9
            obj = c.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return obj;
    }

    public <T> void fun1(T obj) {
        System.out.println(obj.getClass());
    }

    public static void main(String[] args) {
        //Class cls1 = Student.class;
        Student stu = getObj(Student.class);
        Teacher tea = getObj(Teacher.class);

        //fun1(stu);
        //fun1(tea);
    }
}





